//
//  LCTabBarVC.m
//  LongChain
//
//  Created by FengZi on 2018/3/19.
//  Copyright © 2018年 FengZi. All rights reserved.
//

#import "LCTabBarVC.h"
#import "LCUserModel.h"

@interface LCTabBarVC ()<UITabBarDelegate,UITabBarControllerDelegate>

@end

@implementation LCTabBarVC
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self;
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

        UIImage *image = obj.image;
        image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        obj.image = image;

    }];
    
    NSArray *array =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *fileName = [array.firstObject stringByAppendingPathComponent:@"userModel"];

    //解档
    NSData *undata = [[NSData alloc] initWithContentsOfFile:fileName];
    //解档辅助类
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:undata];
    //解码并解档出model
    LCUserModel *unModel = [unarchiver decodeObjectForKey:@"userModel"];
//    [LCUserModel userModelManager].mobile = unModel.userPhone;
//    [LCUserModel userModelManager].userid = unModel.userToken;
    NSLog(@"%@",unModel);
    //关闭解档
    [unarchiver finishDecoding];
}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    
    if (viewController == self.viewControllers[1]) {
        
        UIViewController *VC = self.viewControllers[1];
        VC.view.backgroundColor = RGBAlpha(0, 0, 0, 0.5);
        [[UIApplication sharedApplication].keyWindow addSubview:VC.view];
        LCLog(@"点击中间按钮");
        return NO;
    }
    
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//    LCLog(@"111 = %@",viewController);
//    LCLog(@"yang = %@",self.title);

    
//    NSInteger selectedIndex = self.selectedIndex;
//    switch (selectedIndex) {
//        case 0:
//        {
//            [self.tabBarItem setSelectedImage:[[UIImage imageNamed:@"cloudPlatesSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];//选中图片
//            
//        }
//            break;
//        case 1:
//        {
//            
//        }
//            break;
//        case 2:
//        {
//            [self.tabBarItem setSelectedImage:[[UIImage imageNamed:@"mineSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];//选中图片
//            
//        }
//            break;
//            
//        default:
//            break;
//    }

    
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    
    LCLog(@"%@",item);
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
